package com.greenyoung.pwiki.elasticsearch.index.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenyoung.pwiki.common.utils.PageUtils;
import com.greenyoung.pwiki.elasticsearch.index.dao.ElIndexRecordDao;
import com.greenyoung.pwiki.elasticsearch.index.entity.ElIndexRecordEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("elIndexRecordService")
public class ElIndexRecordService extends ServiceImpl<ElIndexRecordDao, ElIndexRecordEntity> implements com.greenyoung.pwiki.elasticsearch.index.service.ElIndexRecordService {
//    @Autowired

    //TODO：加userId判断
    @Override
    public Map<String, Integer> queryElIndexCount(Long userId) {
        Map<String, Integer> map = new HashMap<>();

        QueryWrapper<ElIndexRecordEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0);
        Integer indexingCount = baseMapper.selectCount(queryWrapper);
        map.put("indexingCount", indexingCount);

        queryWrapper.clear();
        queryWrapper.eq("status", -1);
        Integer failedCount = baseMapper.selectCount(queryWrapper);
        map.put("failedCount", failedCount);

        queryWrapper.clear();
        queryWrapper.eq("status", 1);
        Integer successCount = baseMapper.selectCount(queryWrapper);
        map.put("successCount", successCount);

        return map;
    }

    @Override
    public PageUtils queryIndexingRecordPage(Long userId) {
        return null;
    }
}
